package com.jk.controller;

import com.jk.flower.mapper.FlowerRepo;
import com.jk.flower.pojo.Flower;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("mall")
public class ShoppingM {

    @Autowired
    FlowerRepo flowerRepo;

    @RequestMapping("shopping/{type}")
    public String toShoppingmall(Model model, @PathVariable("type") int type){
        List<Flower> flowerList = flowerRepo.findAll();
        List<Flower> toList = new ArrayList<>();
        for(int i = 0; i <flowerList.size(); i++){
            Flower f = flowerList.get(i);
            if(f.getType() == type){
                toList.add(f);
            }
        }
        model.addAttribute("flowerAllList",toList);
        if(type == 0){
            return "main/product";
        }else if(type == 1){
            return "main/productfl";
        }
        return null;

    }


}
